<?php
namespace app\admin\controller;
class Useruplevel extends Base
{
    //列表
    public function lists(){
        if(is_post()){
            $d = $this->post;
            $map = [];
            if($d['keyword']!=''){ $map[] = ['and','b.username|c.username','like',"%{$d['keyword']}%"]; }
            if($d['min_time']!='') $map[] = ['and','a.create_time','>=',strtotime($d['min_time'])];
            if($d['max_time']!='') $map[] = ['and','a.create_time','<=',strtotime($d['max_time'])];
            $w  = where($map);
            $sql = "
            select
                a.*,b.username,c.username as s_username
            from
                user_up_level a
            left join
                user b on a.user_id = b.id
            left join
                user c on a.s_id = c.id
            $w[0]
            order by a.id desc".limit($d['page'],$d['limit']);
            $rs = $this->db->query($sql, $w[1],'',true);

            if($rs){
                foreach($rs[0] as $k => $v){
                    $rs[0][$k]['before_level']  = c("type.user_level")[$v['before_level']];
                    $rs[0][$k]['after_level']  = c("type.user_level")[$v['after_level']];
                    $rs[0][$k]['create_time'] = com_time_format($v['create_time']);
                }
                suc($rs[0],$rs[1]);
            }else{
                suc([],0);
            }
            $this->fetch();
        }
        return $this->fetch();
    }
}
?>
